<template>
<div>
  <div class="row-header" >
    <el-form :inline="$store.state.app.screenWidth<500?false:true" label-width="50px" :label-position="$store.state.app.screenWidth<500?'top':'right'" :style="{'margin-left':$store.state.app.screenWidth<500?'10px':'auto'}">
      <el-form-item label=" ">
        <el-input v-model="cardNumberSearch" placeholder="请输入业务号码" :style="{'width':$store.state.app.screenWidth<500?'80%':'300px'}"></el-input>
      </el-form-item>
      <el-form-item label=" " >
        <el-select v-model="dictCardTypeSearch" placeholder="请选择卡体类型" :style="{'width':$store.state.app.screenWidth<500?'80%':'300px'}">
          <el-option v-for="dictCardType in dictCardTypeSelect" :key="dictCardType.value" :label="dictCardType.label" :value="dictCardType.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label=" ">
        <el-input size="small" v-model="cardNumberStart" placeholder="请输入起始号段" style="width: 200px"></el-input>
        <span style="margin: 0 10px">-</span>
        <el-input size="small" v-model="cardNumberEnd"  placeholder="请输入结束号段" style="width: 200px"></el-input>
      </el-form-item>
    </el-form>
    <div class="row-form-btn">
      <el-button size="small" type="shenda" icon="el-icon-search" @click="currentPage = 1 ; initData()">查询</el-button>
      <el-button size="small" type="shenda" icon="el-icon-download" >导出</el-button>
    </div>
  </div>
  <div class="row-main">
    <el-button type="shenda" size="small" icon="el-icon-back" @click="toBack">返回</el-button>
    <el-button type="shenda" size="small" icon="el-icon-folder-opened" v-has="'backCardButtonPer'">回收物联网卡</el-button>

    <el-table :header-cell-style="{ 'background':$store.state.app.tableBgColor,'color':'#606266' }" :data="tableData" tooltip-effect="dark" class="row-main-table" @selection-change="handleSelectionChange" v-loading.fullscreen="" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.2)">
      <el-table-column type="selection" align="center" :fixed="$store.state.app.screenWidth<992?true:false" width="80px"></el-table-column>
      <el-table-column prop="cardNumber" label="业务号码" align="center" :width="$store.state.app.screenWidth<992?'180px':'auto'"></el-table-column>
      <el-table-column prop="dictCardTypeName" label="卡体类型" align="center" :width="$store.state.app.screenWidth<992?'150px':'auto'"></el-table-column>
      <el-table-column prop="cardFlowTotal" label="充值流量" align="center" :width="$store.state.app.screenWidth<992?'150px':'auto'"></el-table-column>
      <el-table-column prop="carFlowSurplus" label="剩余流量" align="center" :width="$store.state.app.screenWidth<992?'150px':'auto'"></el-table-column>
      <el-table-column prop="cardFlowActUsed" label="本月已用" align="center" :width="$store.state.app.screenWidth<992?'150px':'auto'"></el-table-column>
      <el-table-column prop="name" label="操作" align="center" :width="$store.state.app.screenWidth<992?'150px':'auto'">
        <template slot-scope="scope">
          <el-button @click="toEcharts(scope.row)" size="mini">查看流量</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div :style="{'overflow-x':$store.state.app.screenWidth<992?'scroll':'auto'}">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :page-sizes="[10, 20, 50, 100]"
        :total="total"
        background
        class="row-main-pager"></el-pagination>
    </div>
  </div>
</div>
</template>

<script>
  import { listForCard } from '@/api/getData'


export default {
  name: 'Card',
  data() {
    return{
      userId : 0,
      value: false,
      pageSize: 10,
      currentPage: 1,
      total: 1,
      tableData : [],
      multipleSelection:[],
      cardNumberStart:"",
      cardNumberEnd:"",
      cardNumberSearch:"",
      dictCardTypeSearch:"",
      dictCardTypeSelect : [{
        value:"",
        label:"请选择卡体类型"
      } , {
        value:"MP1SINGLE",
        label:"MP1单切大卡"
      } , {
        value:"MP2SINGLE",
        label:"MP2单切大卡"
      } , {
        value:"MP1DOUBLE",
        label:"MP1双切卡"
      } , {
        value:"MP2DOUBLE",
        label:"MP2双切卡"
      } , {
        value:"MP1TRIPLE",
        label:"MP1三切卡"
      } , {
        value:"MP2TRIPLE",
        label:"MP2三切卡"
      } , {
        value:"MP1MICRO",
        label:"MP1 Micro卡"
      } , {
        value:"MP2MICRO",
        label:"MP2 Micro卡"
      } , {
        value:"MP1NANO",
        label:"MP1 Nano卡"
      } , {
        value:"MP2NANO",
        label:"MP2 Nano卡"
      } , {
        value:"MS056",
        label:"MS0 5*6"
      } , {
        value:"MS156",
        label:"MS1 5*6"
      } , {
        value:"MS055",
        label:"MS0 5*5"
      } , {
        value:"MS155",
        label:"MS1 5*5"
      }]
    }
  },
  created () {
    this.userId = this.$route.params.userId
    this.initData();
    //console.log(this.userId)
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
      this.initData();
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.initData()
    },
    toEcharts(card) {
      this.$router.push({ path: '/user/echarts/'+card.id })
    },
    // 页面初始化
    async initData(theKey) {
      const returnData = await listForCard({
        currentUserId:this.userId,
        dictCardType:this.dictCardTypeSearch,
        cardNumberStart:this.cardNumberStart,
        cardNumberEnd:this.cardNumberEnd,
        cardNumber:this.cardNumberSearch,
        page: {
          current: this.currentPage + '',
          size: this.pageSize + ''
        }
      }, {
        obj: this,
        key: 'tableLoading;' + theKey
      })
      this.tableData = []
      if (returnData._result) {
        this.total = returnData.data.total // 分页的最大页数
        // 数据回显
        returnData.data.records.map(item => {
          const obj = {}
          obj.id = item.id
          obj.cardNumber = item.cardNumber // 业务号码
          obj.cardUse = item.cardUse // 备注
          obj.dictCardTypeName = item.dictCardTypeName //卡体类型
          obj.cardFlowTotal = item.cardFlowTotal // 总量
          obj.carFlowSurplus = item.carFlowSurplus // 剩余用量
          obj.cardFlowUsed = item.cardFlowUsed // 使用流量（虚量）
          obj.cardFlowActUsed = item.cardFlowActUsed // 使用流量（实际）
          this.tableData.push(obj)
        })
        this.tableLoading = false
      }
    },
    toBack() {
      this.$router.back(-1)
    }
  }
}
</script>

<style scoped lang="scss">

.el-picker-panel.el-date-range-picker.el-popper {
  margin-left: 310px;
}

.app-wrapper.openSidebar {
  .select /deep/ span {
    width: 14%;
  }
}
.el-popper[x-placement^=top] {
  box-shadow: 0px 0px 10px #888888;
  margin-left: 6px;
  margin-right: -39px;
  button {
    display: block;
  }
  .operation {
    border: 0;
    outline: none;
    display: block;
    text-align: center;
    margin: 0;
  }
}
</style>
